

function initHeader() {
	$.ajax({
		url: "/common/header.html",
		cache: true,
		async: true,
		success: function (html) {
			$("body").prepend(html);
		}
	});
}

function uiSuccess(content, cap) {
	cap = cap ? cap : "成功";
	$.Notify({
		caption: cap,
		content: content,
		type: 'success'
	});

}

function uiAlert(content, cap) {
	cap = cap ? cap : "异常";
	$.Notify({
		caption: cap,
		content: content,
		type: 'alert',
		keepOpen: true
	});

}



function resizeAll() {

    var sw = window.screen.width;
    var sh = window.screen.height;

    var fw = sw * 0.6;
    var fh = sh * 0.6;

    var fx = (sw - fw) / 2;
    var fy = (sh - fh) / 2;
    log(fx + ":" + fy);

    win.resizeTo(fw, fh);
    win.moveTo(fx, fy);

}
/**
 * 重置指定元素高度，用parentId减去其他id
 * 
 * @param {}
 *            divId
 * @param {}
 *            parentId
 * @param {}
 *            otherId
 */
function resizeDiv(divId, parentId, otherId) {
    if (arguments.length < 2) {
        throw "参数异常，至少为2个";
    }
    var others = [];
    for (var i = 2; i < arguments.length; i++) {
        others.push(arguments[i]);
    }
    var ph = parseInt($("#" + parentId).height());
    var oh = 0;
    for (var i = 0; i < others.length; i++) {
        oh += parseInt($("#" + others[i]).height());
    }
    $("#" + divId).height(ph - oh).css("overflow", "auto");
}

function log(obj) {
    console.log(obj);
}

function loadPage(path) {
    loadAll();
    $("body").load(path, function() {
                unLoadAll();
            });
}

function goPage(path) {
    loadAll();
    window.location.href = path;
}

function loadAll() {
    $("body").showLoading();
}

function unLoadAll() {
    $("body").hideLoading();
}

function addMouseColor(obj, onColor, outColor) {
    if (!outColor) {
        outColor = $(obj).css("background-color");
    }
    $(obj).mouseover(function() {
                $(this).css("background-color", onColor);
            }).mouseout(function() {
                $(this).css("background-color", outColor);
            });
}

function addMouseCss(obj, onCss, outCss) {
    $(obj).mouseover(function() {
                $(this).css(onCss);
            }).mouseout(function() {
                $(this).css(outCss);
            });
}

function addMouseClass(obj, onCss) {
    $(obj).mouseover(function() {
                $(this).addClass(onCss);
            }).mouseout(function() {
                $(this).removeClass(onCss);
            });
}

function dirChooser(ele, callback) {
    var realChoose = $("#fileDialog");
    if (realChoose.length == 0) {
        var realChoose = $('<input style="display:none;" id="fileDialog" type="file" nwdirectory  />')
                .appendTo($("body"));
    }
    realChoose.change(function(evt) {
                var path = $(this).val()
                path = path.replace(/\//g, "\\\\")
                path = path.replace(/\\/g, "/")
                callback(path);
            });
    $(ele).click(function() {
                realChoose.click();
            });
}

function formatFileSize(size) {
    var g = 1024 * 1024 * 1024;
    var m = 1024 * 1024;
    var k = 1024;
    if (size > g) {
        size = (Math.round(size * 100 / g) / 100) + "G";
    } else if (size > m) {
        size = (Math.round(size * 100 / m) / 100) + "M";
    } else if (size > k) {
        size = (Math.round(size * 100 / k) / 100) + "K";
    } else {
        size = size + "B";
    }
    return size;
}







